<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('add to cart'); ?>
<?php if($_product->isSaleable()): ?>
    <div class="add-to-cart">
        <?php if(!$_product->isGrouped()): ?>		
		<div class="increase">			
			<input type="text" name="qty" readonly="readonly" id="qty-<?php echo $_product->getId()?>" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty"/>
			<span onclick="increaseQty(false, false, false, <?php echo $_product->getId()?>, <?php echo $this->helper('gtgobbler/catalog')->getMaxIncreaseQty($_product)?>)" class="up pointer">up</span>
			<span onclick="decreaseQty(false, false, false, <?php echo $_product->getId()?>)" class="down pointer">down</span>
		</div>
		<?php endif; ?>
        <?php if ($_product->getTypeInstance(true)->hasOptions($_product)):?>
			<button style="width: 168px;" id='mc-<?php echo $_product->getId()?>' class="button arrow-down mcbutton"><span><span>more choices</span></span></button>
			<?php $configurableAttributes = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product)?>
			<div class="select-flavour-container-list" id="flavourc-<?php echo $_product->getId()?>">
			<?php foreach($configurableAttributes as $attribute):?>				
				<table>
					<col />
					<col width="35"/>
					<tbody>
						<?php $f=1;$count=count($attribute['values']);
						foreach($attribute['values'] as $value):?>
							<?php
								$childProduct = $_product->getTypeInstance(true)->getProductByAttributes(array($attribute['attribute_id'] => $value['value_index']), $_product);
								$childProduct = Mage::getModel('catalog/product')->load($childProduct->getId()); 
								if(!$childProduct->isSaleable())
									continue;
							?>
							<tr <?php if($f == $count) echo 'class="last"'?> onclick="addToCartAjax(<?php echo $_product->getId()?>, false, false, false, <?php echo $attribute['attribute_id']?>, <?php echo $value['value_index']?>)">												
								<td class="label">													
									<?php echo $value['label']?>													
								</td>
								<td class="addto">
									<span>add to</span>
									<span class="big">cart</span>
								</td>												
							</tr>
						<?php $f++?>
						<?php endforeach?>
					</tbody>
				</table>				
			<?php endforeach?>
			</div>						
		<?php else:?>
			<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="addToCartAjax(<?php echo $_product->getId()?>, false, false, false)"><span><span><?php echo $this->__('add to cart') ?></span></span></button>
		<?php endif?>
		<?php echo $this->getChildHtml('', true, true) ?>
    </div>	
<?php endif; ?>
